package FanShe2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestBoss {
    public static void main(String[] args)
            throws ClassNotFoundException,
            InstantiationException,
            IllegalAccessException,
            NoSuchMethodException,
            InvocationTargetException {
        //1.获取反射对象
        Class<?> bosscls = Class.forName("FanShe2.Boss");
        //2.实例化Boss对象
        Object o = bosscls.newInstance();

        Method h1 = bosscls.getMethod("hi", String.class);
        h1.invoke(o, "胡志维ssss");

        Method say = bosscls.getDeclaredMethod("say", int.class, String.class, char.class);
        say.setAccessible(true);//私有的需要这句
        System.out.println("say.invoke(0,50,\"a\",'d') = " + say.invoke(0, 50, "a", 'd'));
        Object invoke = say.invoke(0, 18, "胡志维", '女');
        System.out.println("invoke = " + invoke);

        Method m1 = bosscls.getDeclaredMethod("m1");
        Object invoke1 = m1.invoke(o);
        System.out.println("invoke1 = " + invoke1);


    }
}
